package com.mchsdk.paysdk.http.process;

import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;

import com.lidroid.xutils.http.RequestParams;
import com.mchsdk.paysdk.bean.ChannelAndGameInfo;
import com.mchsdk.paysdk.bean.PersonalCenterModel;
import com.mchsdk.paysdk.config.MCHConstant;
import com.mchsdk.paysdk.http.request.CertificateRequest;
import com.mchsdk.paysdk.http.request.RegisterRequest;
import com.mchsdk.paysdk.utils.MCLog;
import com.mchsdk.paysdk.utils.RequestParamUtil;

import org.apache.http.entity.StringEntity;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

public class CertificateProcess {

    private static final String TAG = "CertificateProcess";

    private String idcard;
    private String real_name;


    public void post(Handler handler) {
        if (null == handler) {
            MCLog.e(TAG, "fun#post handler is null");
            return;
        }

        Map<String, String> map = new HashMap<String, String>();
        map.put("idcard", idcard);
        map.put("real_name", real_name);
        map.put("user_id", PersonalCenterModel.getInstance().getUserId());
        map.put("game_id", ChannelAndGameInfo.getInstance().getGameId());


        String param = RequestParamUtil.getRequestParamString(map);
        if (TextUtils.isEmpty(param)) {
            MCLog.e(TAG, "fun#post param is null");
            return;
        }
        RequestParams params = new RequestParams();
        MCLog.w(TAG, "fun#post postSign:" + map.toString());
        try {
            params.setBodyEntity(new StringEntity(param.toString()));
        } catch (UnsupportedEncodingException e) {
            params = null;
            MCLog.e(TAG, "fun#post UnsupportedEncodingException:" + e);
        }

        if (null != params) {
            CertificateRequest certificateRequest = new CertificateRequest(handler);
            certificateRequest.post(MCHConstant.getInstance().getCertificate(), params);
        } else {
            MCLog.e(TAG, "fun#post RequestParams is null");
        }
    }

    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }

    public void setReal_name(String real_name) {
        this.real_name = real_name;
    }
}
